﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;

namespace Rocket.Core
{

    [Serializable]
    public class AdditionalData : Dictionary<string, object>
    {
        public static AdditionalData Resolve(string from)
        {
            if (string.IsNullOrEmpty(from))
                return null;
            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.LoadXml(from);
            AdditionalData addData = new AdditionalData();
            foreach (XmlNode node in xmlDoc.ChildNodes[0].ChildNodes)
                addData.Add(node.Name, node.InnerText);
            return addData;
        }

        public override string ToString()
        {
            if (this.Count == 0) return string.Empty;

            string xmlDoc = "<AdditionalData>";
            foreach (KeyValuePair<string, object> item in this)
            {
                xmlDoc += "<" + item.Key + ">";
                xmlDoc += item.Value;
                xmlDoc += "</" + item.Key + ">";
            }
            xmlDoc += "</AdditionalData>";
            return xmlDoc;
        }
    }
}
